<template>
  <div class="markerRev">
    <div class="dropdown">
      <jc-button
        :btn-arr="['option', 'remove', 'pass', 'hangPass', 'sub', 'save', 'push', 'com3', 'reload', 'list', !list.length && 'check']"
        :disab-arr="['com2', 'freeze', 'using']"
        :fbillno="prodValue.fbillNo"
        :list="'/marketOrder'"
        @refresh="queryTSalOrderNtry"
        @save="subMarker('A')"
        @submit="subMarker('A', 1)"
        @noSubmit="submitMar(2)"
        @audit="audit(1)"
        @noAudit="audit(2)"
        @startUsing="using(1)"
        @forbidden="using(2)"
        @cancellation="cancell(1)"
        @NoCalncellation="cancell(2)"
        @del="delPublic"
        @hangAudit="hangAudit(1)"
        @hangAudit2="hangAudit(2)"
        @handleCom1="queryReportForm1"
        @handleCom3="queryReportForm2"
        @pushDown="pushDown"
        @toExcel="handleExportDetails"
        @check="check('up')"
        @check1="check('down')"
      />
      <el-dropdown size="mini" style="margin: 0 10px" split-button type="primary" trigger="click" @click="copyMarketOrder(0)">
        {{ $t('btn.copy') }}<!--复制-->
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="copyMarketOrder(0)">{{ $t('market.copy') }}<!--复制全部--></el-dropdown-item>
          <el-dropdown-item @click.native="copyMarketOrder(1)">{{ $t('market.copy2') }}<!--复制表头--></el-dropdown-item>
          <el-dropdown-item @click.native="copyMarketOrder(2)">{{ $t('market.copy3') }}<!--复制明细--></el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <el-button type="primary" size="mini" @click="operation">{{ $t('market.sun') }}<!--运算--></el-button>
      <el-button type="primary" size="mini" @click="deliVisible=true">{{ $t('market.upDeliver') }}<!--更新发货期--></el-button>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleTabCli">
      <el-tab-pane class="market" :label="$t('market.info')" name="first" style="height: 120px">
        <el-form ref="purchaseRef" :model="prodValue" size="mini" label-width="100px">
          <el-form-item :label="$t('market.state')">
            <el-tag :type="prodValue.stateColor">
              {{ prodValue.fdocumentStatus }}
            </el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.billType')" prop="fbillTypeName">
            <el-input
              v-model="prodValue.fbillTypeName"
              size="mini"
              disabled
            />
          </el-form-item>
          <el-form-item :label="$t('market.billNo')">
            <el-input v-model="prodValue.fbillNo" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.fdate')" prop="fdate">
            <el-date-picker
              v-model.trim="prodValue.fdate"
              type="date"
              value-format="yyyy-MM-dd"
              size="mini"
              :disabled="isDisabled"
              style="width: 163px"
            />
          </el-form-item>
          <!--          <el-form-item label="销售组织">-->
          <!--            <el-select-->
          <!--              v-model.trim="prodValue.fsaleorgid"-->
          <!--              :disabled="isDisabled"-->
          <!--              @change="saleHeadel"-->
          <!--            >-->
          <!--              <el-option-->
          <!--                v-for="option in teamList"-->
          <!--                :key="option.fid"-->
          <!--                :label="option.fname"-->
          <!--                :value="option.fid"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item :label="$t('market.cust')" prop="fcustId">
            <el-input v-model.trim="prodValue.fcustName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.headDelivery')" prop="fheadDeliveryWay">
            <el-autocomplete
              v-model.trim="prodValue.fheadDeliveryWayName"
              highlight-first-item
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch2"
              size="mini"
              :disabled="isDisabled"
              @focus="queryFheadDelivery"
              @select="deliveData"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="deliveVisiblit=true"
              />
              <template slot-scope="{ item }">
                <div class="name">{{ item.fdataValue }}</div>
              </template>
            </el-autocomplete>
          </el-form-item>
          <el-form-item :label="$t('market.saler')" prop="fsalerId">
            <el-autocomplete
              v-model.trim="prodValue.fsalerName"
              highlight-first-item
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch3"
              size="mini"
              :disabled="isDisabled"
              @focus="querySalesperson(1)"
              @select="marketData"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="marketVisiblit=true"
              />
              <template slot-scope="{ item }">
                <div class="name">{{ item.fuserName }}</div>
              </template>
            </el-autocomplete>
          </el-form-item>
          <el-form-item :label="$t('market.recCondition')" prop="frecConditionId">
            <el-autocomplete
              v-model.trim="prodValue.freccondiTionName"
              highlight-first-item
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch4"
              size="mini"
              :disabled="isDisabled"
              @focus="querytReccondition"
              @select="gatheringData"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="gatheringVisiblit=true"
              />
              <template slot-scope="{ item }">
                <div class="name">{{ item.fname }}</div>
              </template>
            </el-autocomplete>
          </el-form-item>
          <el-form-item :label="$t('market.paezCom')" prop="F_PAEZ_COMBO">
            <el-select
              v-model="prodValue.F_PAEZ_COMBO"
              size="mini"
              filterable
              :disabled="isDisabled"
            >
              <el-option
                v-for="item in standard"
                :key="item.fid"
                :label="item.fname"
                :value="item.fid"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('market.paezText')" prop="F_PAEZ_TEXT">
            <el-input
              v-model.trim="prodValue.F_PAEZ_TEXT"
              size="mini"
              :disabled="isDisabled"
            />
          </el-form-item>
          <el-form-item :label="$t('market.paezText1')" prop="F_PAEZ_TEXT1">
            <el-input
              v-model.trim="prodValue.F_PAEZ_TEXT1"
              size="mini"
              :disabled="isDisabled"
            />
          </el-form-item>
          <el-form-item :label="$t('market.paezText2')" prop="F_PAEZ_TEXT2" label-width="5.5vw">
            <el-input
              v-model.trim="prodValue.F_PAEZ_TEXT2"
              size="mini"
              :disabled="isDisabled"
            />
          </el-form-item>
          <el-form-item :label="$t('market.gold')" prop="fgold">
            <el-input
              v-model.trim.number="prodValue.fgold"
              :disabled="isDisabled"
              size="mini"
            />
          </el-form-item>
          <el-form-item :label="$t('market.note')" prop="fnote" style="width: 33.2%">
            <el-input
              v-model.trim="prodValue.fnote"
              size="mini"
              :disabled="isDisabled"
              style="height: 35px"
            />
          </el-form-item>
          <el-form-item :label="$t('market.salOrder')">
            <el-button
              v-if="button('salOrder:type')"
              class="btnType"
              type="primary"
              size="mini"
              @click="checkSaler"
            ><!--切换-->{{ $t('market.cut') }}</el-button>
            <el-tag v-if="prodValue.saler" type="success">{{ $t('market.sucOrder') }}<!--正常订单--></el-tag>
            <el-tag v-if="!prodValue.saler" type="danger">{{ $t('market.dangOrder') }}<!--特批订单--></el-tag>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane class="market" :label="$t('market.fince')" name="second">
        <el-form ref="purchaseRef" :model="prodValue" size="mini" label-width="100px">
          <!--          <el-form-item label="结算组织">-->
          <!--            <el-select v-model.trim="prodValue.fsettleorgid" disabled>-->
          <!--              <el-option-->
          <!--                v-for="option in teamList"-->
          <!--                :key="option.fid"-->
          <!--                :label="option.fname"-->
          <!--                :value="option.fid"-->
          <!--              />-->
          <!--            </el-select>-->
          <!--          </el-form-item>-->
          <el-form-item :label="$t('market.settleCurr')" prop="fsettleCurrId">
            <el-input v-model.trim="prodValue.fsettleCurrName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.exchangeType')">
            <el-input v-model="prodValue.fexchangeTypeName" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.localCurr')">
            <el-input v-model="prodValue.flocalCurrName" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.exchangeRate')">
            <el-input v-model="prodValue.fexchangeRate" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.priceList')" prop="fpriceListId">
            <el-autocomplete
              v-model.trim="prodValue.fpriceListName"
              highlight-first-item
              popper-class="my-autocomplete"
              :fetch-suggestions="querySearch17"
              size="mini"
              :disabled="isDisabled"
              @focus="queryPricerList"
              @select="stickerHandel"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="handelPrice"
              />
              <template slot-scope="{ item }">
                <div class="name">{{ item.fname }}</div>
              </template>
            </el-autocomplete>
          </el-form-item>
          <el-form-item v-if="bomCost('sal:taxamount')" :label="$t('market.billtaxamount')">
            <el-input v-model="prodValue.fbilltaxamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biamount')" :label="$t('market.billamount')">
            <el-input v-model="prodValue.fbillamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biallamount')" :label="$t('market.billallamount')">
            <el-input v-model="prodValue.fbillallamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:taxamount_c')" :label="$t('market.billtaxamount_lc')">
            <el-input v-model="prodValue.fbilltaxamount_lc" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biamount_c')" :label="$t('market.billamount_lc')">
            <el-input v-model="prodValue.fbillamount_lc" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biallamount_c')" :label="$t('market.billallamount_lc')">
            <el-input v-model="prodValue.fbillallamount_lc" disabled />
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane class="market" :label="$t('market.other')" name="third" style="height: 120px">
        <jc-form :options="otherOptions" :option-value="otherUrlObject" label-width="100px" />
      </el-tab-pane>
      <el-tab-pane :label="$t('market.overImg')" name="img" class="disRow">
        <div class="positRe">
          <el-upload
            class="avatar-uploader"
            :action="actionURL"
            :show-file-list="false"
            :auto-upload="false"
            :on-change="modifyExamine"
            :disabled="isDisabled"
          >
            <img
              v-if="prodValue.fapprovalImage"
              :src="prodValue.fapprovalImage"
              class="avatar"
              alt="审批图片"
            >
            <div v-if="prodValue.fapprovalImage" class="magnify">
              <i class="el-icon-search" @click.stop="proviewImg(prodValue.fapprovalImage)" />
              <i class="el-icon-delete" @click.stop="prodValue.fapprovalImage=''" />
            </div>
            <i v-else class="el-icon-plus avatar-uploader-icon"><span>{{ $t('market.upload') }}</span></i>
          </el-upload>
        </div>
      </el-tab-pane>
    </el-tabs>
    <tab
      v-show="active === 1"
      ref="tab"
      :team-list="teamList"
      :msg="saleDetails"
      :msg2="prodValue"
      :forgid="prodValue.fsaleorgid"
      :is-disabled="isDisabled"
      :standard-price="standardPrice"
      :other-log-table-data="otherLogTableData"
      :active="activeName1"
      :typeid="prodValue.fbillTypeName"
      @visible="handlechange"
      @entry="fentry"
      @page="pagintion"
    />
    <!--交货方式列表-->
    <deliver v-if="deliveVisiblit" @delive="deliveData" />
    <!--销售员列表-->
    <market v-if="marketVisiblit" @market="marketData" />
    <!--收款条件列表-->
    <gathering v-if="gatheringVisiblit" @gathering="gatheringData" />
    <!--价目列表-->
    <price v-if="priceVisiblit" :msg2="prodValue.fsettleCurrId" :fcust-id="prodValue.fcustId" @price="stickerHandel" />
    <!--图纸预览-->
    <el-dialog
      v-dialogDrag
      :title="$t('market.preview')"
      model
      :visible.sync="imgVisible"
      append-to-body
      top="10vh"
      width="60%"
    >
      <img :src="priview" alt="预览图片">
    </el-dialog>
    <!-- 下推 -->
    <el-dialog
      v-dialogDrag
      :title="$t('market.checkBill')"
      model
      :visible.sync="isdanjuDialog"
      :close-on-click-modal="false"
      width="600px"
      center
    >
      <div style="text-align: center;height: 100px;line-height: 100px">
        <el-radio-group v-model="orderLX" @change="orderWat">
          <el-radio v-for="item in receipts" :key="item" :label="item">{{ item }}</el-radio>
        </el-radio-group>
      </div>
      <hr>
      <div style="text-align: center;">
        {{ $t('market.rule') }}
        <el-input v-model="convert" size="mini" disabled style="width: 178px;margin-bottom: 5px;" />
        <br>
        {{ $t('market.billType') }}
        <el-select
          v-model.trim="fbillTypeId"
          size="mini"
          filterable
        >
          <el-option
            v-for="(item, index) in billTypeData"
            :key="index"
            :label="item.fname"
            :value="item.fid"
          />
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isdanjuDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="pushDownOrder()">{{ $t('btn.confirm') }}</el-button>
      </span>
    </el-dialog>
    <!-- 更新发货期 -->
    <el-dialog
      v-dialogDrag
      :title="$t('market.upDeliver')"
      model
      :visible.sync="deliVisible"
      append-to-body
      top="10vh"
      width="500px"
      center
    >
      <div>
        <span style="width: 80px;margin-right: 10px">{{ $t('market.fdate') }}</span>
        <el-date-picker
          v-model="fdeliveryDate"
          type="date"
          value-format="yyyy-MM-dd"
          size="mini"
        />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="deliVisible = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="uploadDeliver()">{{ $t('btn.confirm') }}</el-button>
      </span>
    </el-dialog>
    <upDown v-if="upDownVis" :msg="cha" :fentryid="fentryData" @client="upDownVis=false" />
  </div>
</template>
<script>
import {
  queryTSalOrderNtry,
  updateSalOrder,
  querySalOrderLog,
  notReviewSalorder,
  notsubmitSaleOrder,
  submitSaleOrder,
  deleteSalOrder,
  reviewSalorder,
  ableSaleOrder,
  disableSaleOrder,
  updateSalType,
  cancelSaleOrder,
  unCancelSaleOrder,
  queryOrgDetail, updateSalDate,
  audit, reAudit, update
} from '@/api/marketManage/marketOrder'
import jcForm from '@/components/Form'
import jumpMateriel from '@/components/JumpMateriel'
import tab from '@/views/market/marketManage/marketRevising/components/tab'
import mixinsImg from '@/views/market/marketManage/createMarkerOrder/components/mixinsImg'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'
import { toMxAmina } from '@/components/ToMxamineState'
import operability from '@/mixin/Operability'
import jcButton from '@/components/Button'
import mixinShare from '@/views/market/marketManage/createMarkerOrder/components/mixinShare'
import bility from '@/mixin/Operability'
import { export_json_to_excel, formatJson } from '@/utils/Export2Excel'

export default {
  name: 'MarketRevising',
  components: {
    tab,
    jcForm,
    upDown: () => import('@/components/upDown'),
    deliver: () => import('@/views/market/marketManage/createMarkerOrder/components/deliver'),
    market: () => import('@/views/market/marketManage/createMarkerOrder/components/market'),
    gathering: () => import('@/views/market/marketManage/createMarkerOrder/components/gathering'),
    jcButton,
    price: () => import('@/views/market/marketManage/createMarkerOrder/components/price')
  },
  mixins: [jumpMateriel, mixinsImg, autocomplete, operability, mixinShare, bility],
  props: {
    list: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      fdeliveryDate: '',
      upDownVis: false,
      deliVisible: false,
      cha: '',
      active: 1,
      activeName: 'first',
      activeName1: 'first',
      targerName: 'market',
      orderLX: this.$t('menu.purOrderAsi'),
      receipts: [this.$t('menu.purOrderAsi'), this.$t('menu.deliveryRelease')], // 下推  '采购订单''发货通知单'
      fentryData: [],
      billTypeData: [],
      fbillTypeId: 159,
      convert: this.$t('market.xafa'),
      isdanjuDialog: false, // 单据类型
      priview: '', // 预览图片
      imgVisible: false, // 预览图片
      actionURL: '',
      isDisabled: false,
      clientVisiblit: false, // 客户列表弹窗
      priceVisiblit: false, // 价目列表弹窗
      deliveVisiblit: false, // 交货方式弹窗
      marketVisiblit: false, // 销售员弹窗
      currencyVisiblit: false, // 结算币别弹窗
      gatheringVisiblit: false, // 收款条件弹窗
      tableHeard1: [], // 明细信息
      tableHeader2: [], // 收款计划
      standard: [], // 品质标准
      // 点击行的序号
      tableIndex: 0,
      billtypes: [], // 单据类型
      teamList: [], // 组织
      prodValue: { flocalCurrId: '' }, // 表单数据
      fapprovalImage: '',
      saleDetails: [], // 明细数据
      otherOptions: {},
      otherUrlObject: {}, // 其它审核人
      otherLogTableData: {
        array: [],
        total: 0
      }, // 日志数据
      pageNum: 1,
      size: 10,
      total: 0,
      standardPrice: {
        fcustId: '',
        fsettleCurrIdName: '',
        fsysmbol: '',
        fexchangeRate: '',
        flocalCurrId: '',
        fsettleCurrId: '',
        fexchangeTypeId: ''
      }
    }
  },
  created() {
    this.queryFpaezCombo() // 品质标准
    this.queryTSalOrderNtry() // 获取订单列表数据
  },
  methods: {
    // 监听组织
    saleHeadel(forgid) {
      this.prodValue.fsettleorgid = this.prodValue.fsaleorgid
      queryOrgDetail({ forgid }).then(res => {
        if (res.code === 0) {
          this.prodValue = {
            ...this.prodValue,
            ...res.data
          }
        }
      })
    },
    // 运算 跳转MRP
    operation() {
      this.$router.push({ name: 'MrpView', params: {
        XSDDH: this.prodValue.saleDetails
      }
      })
    },
    // 更改订单类型
    checkSaler() {
      this.prodValue.saler = !this.prodValue.saler
      const DATA = {
        fid: this.prodValue.fid,
        fsaltype: this.prodValue.saler ? 0 : 1
      }
      updateSalType(DATA).then(res => {
        if (res.code === 0) {
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
        }
      })
    },
    // 获取订单列表数据
    async queryTSalOrderNtry() {
      const id = this.$route.params.id
      const DATA = { fid: id }
      const { data: RES } = await queryTSalOrderNtry(DATA)
      if (RES.header.fsaltype === 0) {
        RES.header.saler = true
      } else {
        RES.header.saler = false
      }
      this.prodValue = toMxAmina(RES.header)
      this.prodValue.frecConditionId = RES.header.freccondiTionId
      this.prodValue.F_PAEZ_COMBO = Number(RES.header.F_PAEZ_COMBO)
      this.isDisabled = this.prodValue.fdocumentStatus === this.$t('market.state1') || this.prodValue.fdocumentStatus === this.$t('market.state2') ||
        this.prodValue.fdocumentStatus === this.$t('market.state7')
      this.prodValue.saleDetails = RES.details
      this.saleDetails = RES.details
      RES.details.map(res => {
        res.fisFree !== 0 ? res.fisFree = true : res.fisFree = false
        res.frowType = Number(res.frowType)
      })
      this.otherUrlObject = RES.header
      this.standardPrice.fsettleCurrIdName = RES.header.fsettleCurrName
      this.standardPrice.fexchangeRate = RES.header.fexchangeRate
      this.standardPrice.fsettleCurrId = RES.header.fsettleCurrId
      this.standardPrice.fexchangeTypeId = RES.header.fexchangeTypeId
      this.standardPrice.flocalCurrId = RES.header.flocalCurrId
      this.standardPrice.fcustId = RES.header.fcustId
      this.standardPrice.fpriceListId = RES.header.fpriceListId
    },
    // 保存
    subMarker(ev, en) {
      // 订单类型
      if (this.prodValue.saler) {
        this.prodValue.fsaltype = 0
      } else {
        this.prodValue.fsaltype = 1
      }
      // 暂存、下单
      this.prodValue.fdocumentStatus = ev
      this.prodValue.fstart = 0
      const { F_PAEZ_COMBO, F_PAEZ_TEXT, F_PAEZ_TEXT1, F_PAEZ_TEXT2 } = this.prodValue
      const DATA = {
        ...this.prodValue,
        fpaezCombo: F_PAEZ_COMBO,
        fpaezText2: F_PAEZ_TEXT2,
        fpaezText1: F_PAEZ_TEXT1,
        fpaezText: F_PAEZ_TEXT
      }
      this.prodValue.saleDetails.map(item => {
        const { fprice, famount, ftaxrate, F_PAEZ_ASSISTANT } = item
        item.fpaezAssistant = F_PAEZ_ASSISTANT
        item.ftaxPrice = fprice
        item.ftaxAmount = famount
        item.ftaxRate = ftaxrate
      })
      const api = this.isDisabled ? update : updateSalOrder
      api(DATA).then(res => {
        if (res.code === 0) {
          if (en === 1) {
            this.submitMar(1)
          }
          this.$message({
            showClose: true,
            type: 'success',
            message: '操作成功'
          })
          setTimeout(() => {
            this.queryTSalOrderNtry()
          }, 1000)
          // this.$router.push({ path: '/marketNoPass' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
        }
      })
    },
    // 明细信息、收款计划数据
    handlechange(ev) {
      this.prodValue.saleDetails = ev.saleDetails
    },
    // 打开价目表
    handelPrice() {
      if (this.prodValue.fsettleCurrId) {
        this.priceVisiblit = true
      } else {
        this.$message({ showClose: true, message: '请选择结算币别', type: 'warning' })
      }
    },
    handleTabCli(tab) {
      if (tab.name === 'third') {
        this.handleOther()
        this.activeName1 = 'third'
        this.active = 1
      } else if (tab.name === 'first' || tab.name === 'second') {
        this.activeName1 = 'first'
        this.active = 1
      } else if (tab.name === 'img') {
        this.active = 0
      }
    },
    // 日志翻页
    pagintion(ev) {
      this.pageNum = ev.pageNum
      this.size = ev.pageSize
      this.handleOther()
    },
    // 获取其它
    async handleOther() {
      const id = this.prodValue.fbillNo
      const DATA = { pageNum: this.pageNum, pageSize: this.size, fbillNo: id }
      const { data: RES } = await querySalOrderLog(DATA)
      this.total = RES.total
      this.otherLogTableData = RES
      this.otherOptions = {
        fcreator: { label: this.$t('market.creator'), span: 6, disabled: 'disabled' },
        fmodifier: { label: this.$t('market.modifier'), span: 6, disabled: 'disabled' },
        fapprover: { label: this.$t('market.approver'), span: 6, disabled: 'disabled' },
        fforbider: { label: this.$t('market.forbider'), span: 6, disabled: 'disabled' },
        fcreatedate: { label: this.$t('market.createDate'), span: 6, disabled: 'disabled' },
        fmodifydate: { label: this.$t('market.modifyDate'), span: 6, disabled: 'disabled' },
        fapprovedate: { label: this.$t('market.approveDate'), span: 6, disabled: 'disabled' },
        fforbiddate: { label: this.$t('market.forbidDate'), span: 6, disabled: 'disabled' }
      }
    },
    // 查看报表
    queryReportForm1() {
      const FNUMBER = this.prodValue.fbillNo
      this.$router.push({ path: `/marketForm1/${FNUMBER}` })
    },
    // 查看报表
    queryReportForm2() {
      const FNUMBER = this.prodValue.fbillNo
      this.$router.push({ path: `/marketXszxd/${FNUMBER}` })
    },
    // 预览图片
    proviewImg(img) {
      this.imgVisible = true
      this.priview = img
    },
    // 审批通过
    async audit(ev) {
      const api = ev === 1 ? reviewSalorder : notReviewSalorder
      this.toExamineFun(api)
    },
    // 提交、反提交
    async submitMar(ev) {
      const api = ev === 1 ? submitSaleOrder : notsubmitSaleOrder
      this.toExamineFun(api)
    },
    // 启用、禁用
    async using(ev) {
      const api = ev === 1 ? ableSaleOrder : disableSaleOrder
      this.toExamineFun(api)
    },
    // 作废、反作废
    async cancell(ev) {
      const api = ev === 1 ? cancelSaleOrder : unCancelSaleOrder
      this.toExamineFun(api)
    },
    // 明细行审核
    hangAudit(ev) {
      const api = ev === 1 ? audit : reAudit
      this.toExamineFun(api, 2)
    },
    fentry(ev) {
      this.fentryData = ev
    },
    // 复制
    copyMarketOrder(ev) {
      this.$router.push({ path: '/createMarkerOrder', query: {
        fid: this.$route.params.id,
        type: ev
      }})
    },
    // 删除
    delPublic() {
      if (this.isDisabled) {
        this.$confirm('请先反审核后再删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
        return
      }
      const DATA = {
        Numbers: [this.prodValue.fbillNo]
      }
      this.$confirm('确定要删除么？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error'
      }).then(() => {
        deleteSalOrder(DATA).then(res => {
          if (res.code === 0) {
            // 关闭当前页面
            this.$store.dispatch('tagsView/guanbi', this.$route)
            this.$router.push({ path: '/marketOrder' })
            this.$message({ showClose: true, message: res.message, type: 'success' })
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      })
    },
    // 更新发货期
    uploadDeliver() {
      if (this.fentryData.length === 0) {
        this.saleDetails.forEach(res => {
          this.fentryData.push(res.fentryId)
        })
      }
      const DATA = {
        EntryIds: this.fentryData,
        fdeliveryDate: this.fdeliveryDate
      }
      updateSalDate(DATA).then(res => {
        if (res.code === 0) {
          this.deliVisible = false
          this.queryTSalOrderNtry()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    check(ev) {
      if (this.fentryData.length === 0) return
      this.cha = ev
      this.upDownVis = true
    },
    // 导出表格-销售订单明细列表
    handleExportDetails() {
      require.ensure([], () => {
        const tHeader = ['客户订单号', '助记码', '物料编码', '规格', '描述', '单位', '数量', '大货交期', '品质标准', '备注']
        const filterVal = ['', 'fmodel', 'fnumber', 'fspecificaTion', 'fdescripTion', 'funitName', 'fqty', 'fdeliveryDate', 'F_PAEZ_ASSISTANT_NAME', 'fnote']
        if (this.prodValue.saleDetails && this.prodValue.saleDetails.length > 0) {
          const list = this.prodValue.saleDetails
          const data = formatJson(filterVal, list)
          export_json_to_excel(tHeader, data, '销售订单明细列表')
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.markerRev {
  @include listBom;
  .dropdown {
    display: flex;
  }
  .el-tabs {
    &::v-deep .el-tabs__content {
      .market {
        height: 10.04vh;
      }
      overflow-y: auto;
    }
    &::v-deep .el-tabs__item {
      height: 30px;
      line-height: 30px;
    }
    &::v-deep .el-tabs__content {
      padding: 5px 17px;
    }
    .el-tabs ::v-deep .el-tabs__header{
      margin: 0 0 5px;
    }
    .disRow {
      height: calc(100vh - 265px);
      .positRe {
        position: relative;
        margin-left: 100px;
        margin-top: 20px;

        .avatar-uploader .el-upload {
          height: 27.6vh;
          border: 1px dashed #d9d9d9;
          border-radius: 6px;
          cursor: pointer;
          position: relative;
          overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
          border-color: #409EFF;
        }

        .avatar-uploader-icon {
          font-size: 18px;
          color: #8c939d;
          width: 11.96vw;
          height: 27.6vh;
          line-height: 27.6vh;
          text-align: center;
          border: 1px solid #aaa;
          border-radius: 6px;
          background: #eee;

          span {
            color: #409EFF;
          }
        }

        .avatar {
          width: 11.96vw;
          height: 27.6vh;
          display: block;
          border-radius: 6px;
        }

        .avatar-uploader {
          width: 11.96vw;
          height: 100%;
          transition: all 1s;
        }

        .avatar-uploader:hover .magnify {
          display: block;
        }

        .magnify {
          display: none;
          height: 27.6vh;
          width: 11.96vw;
          background-color: rgba(0, 0, 0, .4);
          position: absolute;
          top: 0;
          line-height: 27.6vh;
          border-radius: 6px;

          i {
            font-size: 24px;
            color: #fff;
            padding: 0 15px;
          }
        }
      }
    }
    .el-input::v-deep .el-input__inner {
      height: 30px;
      line-height: 30px;
    }
    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 35px;
        width: 275px;
        margin-bottom: 5px;
        .btnType{
          margin-right: 20px;
        }
        .el-date-editor.el-input{
          width: 100% !important;
        }
        .el-select{
          width: 100%;
        }
      }
    }
  }
}

.el-input__icon {
  cursor: pointer;
}

</style>
